import java.io.*;
import java.util.*;
import java.net.*;
import stock.volume.StockVolumeRecord;
import java.text.DecimalFormat;

import local.util.MyPrint;
import local.util.MyDateFormat;
import local.util.MyStringFormat;

public class VolumeChange
{

    private DecimalFormat twoDigits = new DecimalFormat("0.00");
    private Vector recordVector = new Vector ();
    private String stockSymbol;
    private double averageVolume;
    private String startMonth="12";
    private String startDay="31";
    private static int volumeLimit;
    private static int priceLimit;

    MyStringFormat mf = new MyStringFormat ();

    public static void main(String[] args) {

	StringBuffer sbf = new StringBuffer ();
	sbf.append("===================================================================="+"\n");
	sbf.append("[1] [Tick or Tick File] for detail volume change"+"\n");
	sbf.append("[2] [Tick File] For volume > 5 * average volume"+"\n");
	sbf.append("[3] [Tick File] Short"+"\n");
	sbf.append("[4] [Tick File] Long "+"\n");
	sbf.append("[5] Up Train T chart"+"\n");
	sbf.append("[6] Down T Thart"+"\n");
	sbf.append("[7] 0.01--0.25 Volume > 1M"+"\n");
	sbf.append("[8] [Tick File][Volume Limit][Price Limit] Print Tick "+"\n");
	sbf.append("===================================================================="+"\n");

	if (args.length == 0 ) {
	    MyPrint.mainHelp(sbf);
	    System.exit(0);
	}

	int selection = Integer.parseInt(args[0]);

	if (selection > 10 ) {
	    MyPrint.mainHelp(sbf);
	    System.exit(0);
	}

	String my_tick = null;

	if (selection ==1) {
	    if (args.length < 2 ) {
		MyPrint.mainHelp(sbf);
		System.exit(0);
	    }
	    else {
		my_tick = args[1];
	    }
	}

	if (selection == 8) {
	    if (args.length < 4 ) {
		MyPrint.mainHelp(sbf);
		System.exit(0);
	    }
	    else {
		volumeLimit = Integer.parseInt(args[2]);
		priceLimit  = Integer.parseInt(args[3]);
	    }
	}


	File name = new File ("./Data/"+args[1]);
	Vector record_vector = new Vector();
	double average_volume = 0.00;
	Hashtable tickTable = new Hashtable ();
	int counter = 0;

	if (name.isFile()) {
	
	    System.out.println("Loading file......."+ name.getName());
	  
	    TickFileLoader tickLoader = new TickFileLoader();
	    tickLoader.setFileName(name);
	    tickLoader.loadFile();
	    tickTable = tickLoader.getHashTable();
	    System.out.println("Total Loaded :"+ tickTable.size()+"   Stocks!");

	    VolumeChange vc = new VolumeChange();
	    Enumeration enum = tickTable.keys();  
	
	    while (enum.hasMoreElements()) {
		counter++;
		my_tick= (String)enum.nextElement();

		vc.setTickName(my_tick);
		vc.loadData();
		record_vector = vc.getRecordVector ();
		average_volume = vc.averageVolume(record_vector);
		vc.setAverageVolume (average_volume);

		vc.printChart(record_vector, average_volume, selection);
	
		if (counter%100==0 && !(selection == 8 || selection ==9 || selection ==10)) {
		    System.out.println("So Far Looped: "+ counter);
		}
	    }
	}
	else {
	    System.out.println("Finding record for: "+ args[1]+".....");

	    VolumeChange vc = new VolumeChange();
	    vc.setTickName(my_tick);
	    vc.loadData();
	    record_vector  = vc.getRecordVector ();
	    average_volume = vc.averageVolume(record_vector);
	    vc.setAverageVolume (average_volume);
	    vc.printHead();
	    vc.printRecord(record_vector);
	}
    }

    public void setTickName (String tick) {
	stockSymbol = tick;
    }

    public void setRecordVector (Vector v) {
	recordVector = v;
    }

    public Vector getRecordVector () {
	return recordVector;
    }

    public double getAverageVolume () {
	return averageVolume;
    }

    public void setAverageVolume (double av) {
	averageVolume = av;
    }

    public void loadData () {

	URL url;

	BufferedReader bf_in = null;
	StringTokenizer stk  = null;
	String temps = null;
	String input_line;
	//String s_url = "http://table.finance.yahoo.com/k?s="+stockSymbol+"&g=d";
	
	String s_url = "http://table.finance.yahoo.com/table.csv?a=1&b=1&c=2002&d="+
	               startMonth+"&e="+startDay+"&f=2002&s="+ stockSymbol+"&y=0&g=d";
	
	//http://table.finance.yahoo.com/d?a=9&b=04&c=01&d=5&e=08&f=02&g=d&s=tibx
	StockVolumeRecord sv_record = null;
	Vector v = new Vector (1);

	try {

	    url = new URL(s_url);
	    bf_in = new BufferedReader(new InputStreamReader(url.openStream()));
	   
	    while (((input_line = bf_in.readLine()) != null)) {

		sv_record = new StockVolumeRecord();

		if (input_line.startsWith("Date")) {
		    continue;
		}
		
		stk = new StringTokenizer(input_line, ",");
		int i = 0;
		String text[] = {"","","","","",""};

		while (stk.hasMoreTokens()) {
                        temps = stk.nextToken();
			text[i] = temps;
			i++;
		}
	
		sv_record.setTick(stockSymbol);
		sv_record.setDate(text[0]);
		sv_record.setOpenPrice(Double.parseDouble(text[1]));
		sv_record.setHighPrice(Double.parseDouble(text[2]));
		sv_record.setLowPrice(Double.parseDouble(text[3]));
		sv_record.setClosePrice(Double.parseDouble(text[4]));
	
		if (text[5].equals("n/a")) {
		    text[5]="0";
		}

		sv_record.setVolume(Integer.parseInt(text[5]));

		if(!v.contains(sv_record)) {
		    v.addElement(sv_record);
		}
	    }

	    setRecordVector(v);
	
	} catch ( Exception e ) {
	    System.out.println("loadData()"+e);
	}
    }

    public void printHead() {
	FindGroupName fgname = new FindGroupName();
 
	MyPrint.printLine("=",133);

	System.out.print("===="+stockSymbol+"==="+ stockSymbol+"==="+ stockSymbol+"==="+
			   "   Average Volume=  "+
			   twoDigits.format(averageVolume)+"\t"+ (new Date()).toString());
	System.out.println( fgname.getGroupNameByTick(stockSymbol));
	MyPrint.printLine("=",133);
    }

    public void printTick() {

	System.out.println(stockSymbol);
    }

    private void printChart ( Vector v, double av, int choice) {

	int chose = choice;
	int counter = 0;

	double feb_high          = 0.00;
	double temp1             = 0.00;
	double temp2             = 0.00; 
	double temp3             = 0.00;
	double average_volume    = av;

	long day1v = 0, day2v = 0, day3v = 0;
	long day4v = 0, day5v = 0, day6v = 0;
	long day7v = 0, day8v = 0, day9v = 0, day10v = 0;

	double openp1=0.0, highp1=0.0, lowp1=0.0, closep1=0.0;
	double openp2=0.0, highp2=0.0, lowp2=0.0, closep2=0.0;
	double openp3=0.0, highp3=0.0, lowp3=0.0, closep3=0.0;
	double openp4=0.0, highp4=0.0, lowp4=0.0, closep4=0.0;
	double openp5=0.0, highp5=0.0, lowp5=0.0, closep5=0.0;
	double openp6=0.0, highp6=0.0, lowp6=0.0, closep6=0.0;
	double openp7=0.0, highp7=0.0, lowp7=0.0, closep7=0.0;
	double openp8=0.0, highp8=0.0, lowp8=0.0, closep8=0.0;
	double openp9=0.0, highp9=0.0, lowp9=0.0, closep9=0.0;
	double openp10=0.0, highp10=0.0, lowp10=0.0, closep10=0.0;
	
	day1v = getCertainDaysVolume ( v, 1);
	day2v = getCertainDaysVolume ( v, 2);
	day3v = getCertainDaysVolume ( v, 3);
	day4v = getCertainDaysVolume ( v, 4);
	day5v = getCertainDaysVolume ( v, 5);
	day6v = getCertainDaysVolume ( v, 6);
	day7v = getCertainDaysVolume ( v, 7);
	day8v = getCertainDaysVolume ( v, 8);
	day9v = getCertainDaysVolume ( v, 9);
	day10v= getCertainDaysVolume ( v, 10);

	//openp1 = getCertainDaysOpenPrice (v, 1);
	highp1 = getCertainDaysHighPrice (v, 1);
	lowp1  = getCertainDaysLowPrice  (v, 1);
	closep1= getCertainDaysClosePrice(v, 1);

	//openp1 = getCertainDaysOpenPrice (v, 2);
	highp2 = getCertainDaysHighPrice (v, 2);
	lowp2  = getCertainDaysLowPrice  (v, 2);
	closep2= getCertainDaysClosePrice(v, 2);

	//openp1 = getCertainDaysOpenPrice (v, 3);
	highp3 = getCertainDaysHighPrice (v, 3);
	lowp3  = getCertainDaysLowPrice  (v, 3);
	closep3= getCertainDaysClosePrice(v, 3);
	
	//openp1 = getCertainDaysOpenPrice (v, 4);
	highp4 = getCertainDaysHighPrice (v, 4);
	lowp4  = getCertainDaysLowPrice  (v, 4);
	closep4= getCertainDaysClosePrice(v, 4);

	highp5 = getCertainDaysHighPrice (v, 5);
	lowp5  = getCertainDaysLowPrice  (v, 5);
	closep5= getCertainDaysClosePrice(v, 5);

	highp6 = getCertainDaysHighPrice (v, 6);
	lowp6  = getCertainDaysLowPrice  (v, 6);
	closep6= getCertainDaysClosePrice(v, 6);

	int i = v.size();

	temp1 =  getCertainDaysClosePrice(v, (i-0));
	temp2 =  getCertainDaysClosePrice(v, (i-1));
	temp3 =  getCertainDaysClosePrice(v, (i-2));

	feb_high = Math.max(temp1, temp2);
	feb_high = Math.max(feb_high, temp3);

	

	if (chose == 1) {

	    printHead();
	    printRecord(v);
	}

	if (chose == 2) {
	    counter++;
	    if (counter%100==0) 
	    System.out.println("Searching Volume > 5 * Average Volume");

	    if ((day1v > 5 * av && av > 200000)) {
		printHead();
		printRecord(v);
	    }
	}

	if (chose == 3) {
	    if ((day1v > 5 * av) && ((highp1-lowp1)/highp1> 0.1) && (closep1>15) && 
		((closep1-lowp1)/lowp1<0.02) && av > 500000) {
		printHead();
		printRecord(v);
	    }
	}

	if (chose == 4) {
	    if ((day1v > 5 * av) && (highp1 > lowp1 * 1.1) && ((closep1- lowp1)/lowp1) >= 0.05 && av > 500000) {
		printHead();
		printRecord(v);
	    }
	}

	if (chose == 5) {
	    if (av > 2000000) {
		printHead();
		printRecord(v);
	    }
	}

	if (chose == 6) {

	    if ((day1v > 2 * av) && (closep1 < closep6*0.9) &&
		(closep1 < feb_high*0.5) &&
		(highp1 > lowp1 * 1.1) && (closep1*0.98 <= lowp1)) {

		System.out.println("closep1: "+closep1);
		System.out.println("closep2: "+closep2);
		System.out.println("closep3: "+closep3);
		System.out.println("closep10:"+closep10);
		System.out.println("up:"+twoDigits.format(((closep1-closep10)/closep10)*100)+"%");
		printHead();
		printRecord(v);
	    }
	}

	if (chose == 8) {
	    if ((day1v+day2v+day3v+day4v+day5v+day6v+day7v+day8v+day9v+day10v)/10 > volumeLimit && 
		closep1 < priceLimit) {
		printTick();
	    }
	}
    }

 
    private void printTChart( Vector v, double av) {

	double feb_high          = 0.00;
	double temp1             = 0.00;
	double temp2             = 0.00; 
	double temp3             = 0.00;
	double average_volume    = av;

	long day1v = 0, day2v = 0, day3v = 0;
	long day4v = 0, day5v = 0, day6v = 0;
	long day7v = 0, day8v = 0, day9v = 0, day10v = 0;

	double openp1=0.0, highp1=0.0, lowp1=0.0, closep1=0.0;
	double openp2=0.0, highp2=0.0, lowp2=0.0, closep2=0.0;
	double openp3=0.0, highp3=0.0, lowp3=0.0, closep3=0.0;
	double openp4=0.0, highp4=0.0, lowp4=0.0, closep4=0.0;
	double openp5=0.0, highp5=0.0, lowp5=0.0, closep5=0.0;
	double openp6=0.0, highp6=0.0, lowp6=0.0, closep6=0.0;
	double openp7=0.0, highp7=0.0, lowp7=0.0, closep7=0.0;
	double openp8=0.0, highp8=0.0, lowp8=0.0, closep8=0.0;
	double openp9=0.0, highp9=0.0, lowp9=0.0, closep9=0.0;
	double openp10=0.0, highp10=0.0, lowp10=0.0, closep10=0.0;
	
	day1v = getCertainDaysVolume ( v, 1);
	day2v = getCertainDaysVolume ( v, 2);
	day3v = getCertainDaysVolume ( v, 3);
	day4v = getCertainDaysVolume ( v, 4);
	day5v = getCertainDaysVolume ( v, 5);
	day6v = getCertainDaysVolume ( v, 6);
	day7v = getCertainDaysVolume ( v, 7);
	day8v = getCertainDaysVolume ( v, 8);
	day9v = getCertainDaysVolume ( v, 9);
	day10v= getCertainDaysVolume ( v, 10);

	openp1 = getCertainDaysOpenPrice (v, 1);
	highp1 = getCertainDaysHighPrice (v, 1);
	lowp1  = getCertainDaysLowPrice  (v, 1);
	closep1= getCertainDaysClosePrice(v, 1);

	//openp1 = getCertainDaysOpenPrice (v, 2);
	highp2 = getCertainDaysHighPrice (v, 2);
	lowp2  = getCertainDaysLowPrice  (v, 2);
	closep2= getCertainDaysClosePrice(v, 2);

	//openp1 = getCertainDaysOpenPrice (v, 3);
	highp3 = getCertainDaysHighPrice (v, 3);
	lowp3  = getCertainDaysLowPrice  (v, 3);
	closep3= getCertainDaysClosePrice(v, 3);
	
	//openp1 = getCertainDaysOpenPrice (v, 4);
	highp4 = getCertainDaysHighPrice (v, 4);
	lowp4  = getCertainDaysLowPrice  (v, 4);
	closep4= getCertainDaysClosePrice(v, 4);
	
	closep10= getCertainDaysClosePrice(v, 10);
	int i = v.size();

	temp1 =  getCertainDaysClosePrice(v, (i-0));
	temp2 =  getCertainDaysClosePrice(v, (i-1));
	temp3 =  getCertainDaysClosePrice(v, (i-2));

	feb_high = Math.max(temp1, temp2);
	feb_high = Math.max(feb_high, temp3);

	if (day3v > 3*av && av > 100000 ) {
	    if (lowp3 < openp3 * 0.9) {
		if (closep3 > lowp3 * 1.03 ) {
		    System.out.println("Feb high was : "+feb_high);
		    System.out.println("openp1: "+openp1);
		    System.out.println("closep1: "+closep1);
		    System.out.println("lowp2: "+lowp1);
		    System.out.println("highp3: "+highp1);
		    printHead();
		    printRecord(v);
		}
	    }
	}
    }


    public void printRecord( Vector input_v) {

	System.out.println("   DATE   "+"    OPEN  "+"  HIGH "+"  LOW  "+
			   "   CLOSE  "+"    VOLUME    "+"   CHANGE      "+
			   "  OPEN_CLOSE"+" HL " + "  Money Change " + " CLOSE ");
	MyPrint.printLine("=",133);

	StockVolumeRecord pblank = new StockVolumeRecord();
	int i = 1;
	double last_close_p = 0.00;

	Enumeration penum = input_v.elements();
	while ( penum.hasMoreElements() ) {
	    i++;	    
	    pblank = (StockVolumeRecord) penum.nextElement();
	    last_close_p = getCertainDaysClosePrice (input_v, i);
	    // System.out.println("last close price="+last_close_p);
	    printRecord( pblank, last_close_p);
	}
    }

    public void printRecord( StockVolumeRecord input_record, double last_close_p) {

	StockVolumeRecord blank = input_record;
	double close_p = blank.getClosePrice();

	NasdaqReport naz = new NasdaqReport();
	naz.setNazRecordVector("01/01/2001");
	//System.out.println(naz.getNazChange("2002-09-03"));

	System.out.print(mf.rightIndent(blank.getDate(), 10, ' ')+" ");
	System.out.print(mf.rightIndent(twoDigits.format(blank.getOpenPrice()),7,' ')+" ");
	System.out.print(mf.rightIndent(twoDigits.format(blank.getHighPrice()),7,' ')+" ");
	System.out.print(mf.rightIndent(twoDigits.format(blank.getLowPrice()) ,7,' ')+" ");

	double n1 = 0.0, n2 = 0.0;
	int m = 0;
	String upDown = " ";
	n1 = blank.getVolume();
	n2 = averageVolume;
	m = (int)((n1/n2) * 10);

	if (m==10) {
	    
	    upDown = "      ";    
	    System.out.print(mf.rightIndent(blank.getVolume(),12,' ')+" "+mf.leftIndent(upDown,15,' ')+" ");
	}
	else if (m>10 && m<15) {
	    
	    while ((m-1)>10) {
		upDown += "+";
		m = m-1;
	    }
	    
	    System.out.print(mf.rightIndent(blank.getVolume(),12,' ')+" "+mf.leftIndent(upDown,15,' ')+" ");
	}
	else if (m>15) {
	    while ((m-10)>1) {
		upDown += "X";
		m = m-4;
		if (upDown.length()>11) {
		    break;
		}
	    }
	    System.out.print(mf.rightIndent(blank.getVolume(),12,' ')+" "+mf.leftIndent(upDown,15,' ')+" ");
	}
	else if (m>=9 && m<10){
	    upDown = "      ";    
	    System.out.print(mf.rightIndent(blank.getVolume(),12,' ')+" "+mf.leftIndent(upDown,15,' ')+" ");
	}
	else {
	    
	    while ((m+1)<10) {
		upDown +="-";
		m = m +2; 
	    }
	    
	    System.out.print(mf.rightIndent(blank.getVolume(),12,' ')+" "+mf.leftIndent(upDown,15,' ')+" ");
	}

	if (openCloseChange(blank)>=0) {
	    System.out.print(mf.rightIndent(("+"+(twoDigits.format(openCloseChange(blank)/blank.getOpenPrice()*100)+" %")), 8,' ')+" ");
	}
	else {
	    System.out.print(mf.rightIndent((twoDigits.format(openCloseChange(blank)/blank.getOpenPrice()*100)+" %"),8,' ')+" ");
	}

	if (highLowChange(blank)>=0) {
	    System.out.print(mf.rightIndent(("+"+twoDigits.format(highLowChange(blank)/blank.getHighPrice()*100)+" %"),10,' ')+" ");
	}
	else {
	    System.out.print(mf.rightIndent((twoDigits.format(highLowChange(blank)/blank.getHighPrice()*100)+" %"),10,' ')+" ");
	}

	System.out.print(mf.rightIndent(twoDigits.format((close_p-last_close_p)*n1), 12,' ')+" ");
	System.out.print(mf.rightIndent(twoDigits.format(blank.getClosePrice()) ,7,' ')+" ");

	if (last_close_p>0) {
	    System.out.print(mf.rightIndent((twoDigits.format(100*(close_p-last_close_p)/last_close_p)+" %"), 10,' ')+" ");
	}
	else {
	    System.out.print(mf.rightIndent("0.0 %", 10,' ')+" ");
	}

	System.out.println(mf.rightIndent(naz.getNazChange(MyDateFormat.format1(blank.getDate())),8,' '));
    }

    private String buyOrSell (StockVolumeRecord svRecord) {
	double openp=0.0, highp=0.0, lowp=0.0, closep=0.0;
	int volume = 0;
	String bs = "NOT SURE";

	openp  = svRecord.getOpenPrice();
	highp  = svRecord.getHighPrice();
	lowp   = svRecord.getLowPrice();
	closep = svRecord.getClosePrice();
	volume = svRecord.getVolume();
	System.out.println("average="+ averageVolume);

	if ((closep>(lowp*1.1))&&(volume>(2*averageVolume))) {
	    bs = "BUY";
	}
	else if ((openp>(closep*1.05))&&(volume>(1.2* averageVolume))){
	    bs = "SELL";
	}

	return (bs);
    }

    private double openCloseChange (StockVolumeRecord svRecord) {
	double openp=0.0, highp=0.0, lowp=0.0, closep=0.0;
	int volume = 0; double change = 0;
	String bs = "NOT SURE";

	openp  = svRecord.getOpenPrice();
	highp  = svRecord.getHighPrice();
	lowp   = svRecord.getLowPrice();
	closep = svRecord.getClosePrice();
	volume = svRecord.getVolume();
	change = closep-openp;
	return (change);
    }

    private double highLowChange (StockVolumeRecord svRecord) {
	double openp=0.0, highp=0.0, lowp=0.0, closep=0.0;
	int volume = 0; double change = 0;
	String bs = "NOT SURE";

	openp  = svRecord.getOpenPrice();
	highp  = svRecord.getHighPrice();
	lowp   = svRecord.getLowPrice();
	closep = svRecord.getClosePrice();
	volume = svRecord.getVolume();
	change = highp-lowp;
	return (change);
    }

    private double averageVolume ( Vector inputV) {

	if (inputV == null) {
	    System.out.println("averageVolume: input is null");
	    System.exit(1);
	}

	int i = 0 ;
	double tv = 0.0, av =0.0 ;

	StockVolumeRecord pblank = new StockVolumeRecord();
	Enumeration penum = inputV.elements();

	while ( penum.hasMoreElements() ) {
	    pblank = (StockVolumeRecord) penum.nextElement();
	    tv += pblank.getVolume();
	    i++;
	}

	av = tv/i;
	//System.out.println("average volume="+ av);
	return (av);
    }

    private long getCertainDaysVolume ( Vector inputV, int day) {
	int i = 0 ;
	long dv = 0 ;

	StockVolumeRecord blankRecord = new StockVolumeRecord();
	StockVolumeRecord tempRecord = new StockVolumeRecord();
	Enumeration penum = inputV.elements();

	while ( penum.hasMoreElements()&& i<day) {
	    tempRecord = (StockVolumeRecord) penum.nextElement();
	    i++;
	    if (i==day) {
		blankRecord = tempRecord;
		dv=blankRecord.getVolume();
	    }
	}
	//System.out.println("The day:"+day+" volume is:" + dv);
	return (dv);
    }

    private double getCertainDaysOpenPrice ( Vector inputV, int day) {
	int i = 0 ;
	double op = 0 ;

	StockVolumeRecord blankRecord = new StockVolumeRecord();
	StockVolumeRecord tempRecord = new StockVolumeRecord();
	Enumeration penum = inputV.elements();

	while ( penum.hasMoreElements()&& i<day) {
	    tempRecord = (StockVolumeRecord) penum.nextElement();
	    i++;
	    if (i==day) {
		blankRecord = tempRecord;
		op=blankRecord.getOpenPrice() ;
	    }
	}
	//System.out.println("The day:"+day+" volume is:" + dv);
	return (op);
    }


    private double getCertainDaysClosePrice ( Vector inputV, int day) {
	int i = 0 ;
	double cp = 0 ;

	StockVolumeRecord blankRecord = new StockVolumeRecord();
	StockVolumeRecord tempRecord = new StockVolumeRecord();
	Enumeration penum = inputV.elements();

	while ( penum.hasMoreElements()&& i<day) {
	    tempRecord = (StockVolumeRecord) penum.nextElement();
	    i++;
	    if (i==day) {
		blankRecord = tempRecord;
		cp=blankRecord.getClosePrice() ;
	    }
	}
	//System.out.println("The day:"+day+" volume is:" + dv);
	return (cp);
    }

   private double getCertainDaysLowPrice ( Vector inputV, int day) {
	int i = 0 ;
	double lp = 0 ;

	StockVolumeRecord blankRecord = new StockVolumeRecord();
	StockVolumeRecord tempRecord = new StockVolumeRecord();
	Enumeration penum = inputV.elements();

	while ( penum.hasMoreElements()&& i<day) {
	    tempRecord = (StockVolumeRecord) penum.nextElement();
	    i++;
	    if (i==day) {
		blankRecord = tempRecord;
		lp=blankRecord.getLowPrice() ;
	    }
	}
	//System.out.println("The day:"+day+" volume is:" + dv);
	return (lp);
    }

   private double getCertainDaysHighPrice ( Vector inputV, int day) {
	int i = 0 ;
	double hp = 0 ;

	StockVolumeRecord blankRecord = new StockVolumeRecord();
	StockVolumeRecord tempRecord = new StockVolumeRecord();
	Enumeration penum = inputV.elements();

	while ( penum.hasMoreElements()&& i<day) {
	    tempRecord = (StockVolumeRecord) penum.nextElement();
	    i++;
	    if (i==day) {
		blankRecord = tempRecord;
		hp=blankRecord.getHighPrice() ;
	    }
	}
	//System.out.println("The day:"+day+" volume is:" + dv);
	return (hp);
    }
}





